package com.cskaoyan.service.wx.sl;

import com.cskaoyan.bean.Region;
import com.cskaoyan.bean.RegionExample;
import com.cskaoyan.mapper.RegionMapper;
import com.cskaoyan.vo.wx.sl.WxRegionListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WxRegionListServiceImpl implements WxRegionListService {

    @Autowired
    RegionMapper regionMapper;

    //显示新建地址时的，各省市信息
    @Override
    public List<WxRegionListVo> queryRegionList(Integer pid) {
        RegionExample regionExample = new RegionExample();
        RegionExample.Criteria criteria = regionExample.createCriteria();
        criteria.andPidEqualTo(pid);
        List<Region> regionList = regionMapper.selectByExample(regionExample);
        //迭代取出我们要的
        List<WxRegionListVo> wxRegionListVos = new ArrayList<WxRegionListVo>();
        for (Region region : regionList) {
            Integer id = region.getId();
            Integer pid1 = region.getPid();
            String name = region.getName();
            Byte type = region.getType();
            Integer code = region.getCode();
            WxRegionListVo wxRegionListVo = new WxRegionListVo(id,pid1,name,type,code);
            wxRegionListVos.add(wxRegionListVo);
        }
        return wxRegionListVos;
    }


}
